package com.bleeth.fx.demo1;

import com.bleeth.fx.helper.ControlsHelper;
import com.bleeth.fx.layout.FormBuilder;
import com.bleeth.fx.layout.GirdCell;
import com.bleeth.fx.meta.View;
import javafx.application.Application;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.SnapshotParameters;
import javafx.scene.control.TextField;
import javafx.scene.effect.BoxBlur;
import javafx.scene.effect.Effect;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;


/**
 * @author Sakura
 * @version 1.0
 * @date 2021-11-13 22:17
 **/
@View("login")
public class LoginView extends Application {

    private StringProperty userProperty = new SimpleStringProperty();

    private StringProperty passwordProperty = new SimpleStringProperty();

    public Region show(Property... properties) {
//        userProperty.bindBidirectional(properties[0]);
//        passwordProperty.bindBidirectional(properties[1]);

        TextField username = ControlsHelper.createTextField("", "用户名", "", "h5");
        TextField password = ControlsHelper.createPasswordField("");
        username.textProperty().bindBidirectional(userProperty);
        password.textProperty().bindBidirectional(passwordProperty);

        VBox loginForm = FormBuilder.form(400D, 400D)
                .addEmptyRow(10D)
                .addRow(GirdCell.createCell(1, Pos.CENTER), GirdCell.createCell(8, Pos.CENTER_LEFT), GirdCell.createCell(1, Pos.CENTER))
                .addCell(1, ControlsHelper.createLabel("登录", "", "h3"))
                .endRow(false)
                .addEmptyRow(20D)
                .addRow(GirdCell.createCell(1, Pos.CENTER), GirdCell.createCell(8, Pos.CENTER_LEFT), GirdCell.createCell(1, Pos.CENTER))
                .addCell(1, ControlsHelper.createLabel("你若不离不弃，我必生死相依", "", "h5"))
                .endRow(false)
                .addEmptyRow(20D)
                .addRow(GirdCell.createCell(1, Pos.CENTER), GirdCell.createCell(8, Pos.CENTER_LEFT), GirdCell.createCell(1, Pos.CENTER))
                .coverCell(1, username)
                .endRow(false)
                .addEmptyRow(20D)
                .addRow(GirdCell.createCell(1, Pos.CENTER), GirdCell.createCell(8, Pos.CENTER_LEFT), GirdCell.createCell(1, Pos.CENTER))
                .coverCell(1, password)
                .endRow(false)
                .addEmptyRow(20D)
                .addRow(GirdCell.createCell(1, Pos.CENTER), GirdCell.createCell(3, Pos.CENTER_LEFT), GirdCell.createCell(1, Pos.CENTER),
                        GirdCell.createCell(4, Pos.CENTER_RIGHT), GirdCell.createCell(1, Pos.CENTER))
                .addCell(1, ControlsHelper.createTextField("", "", "", "h5"))
                .addCell(3, ControlsHelper.createWrapperImg("flowers.png", 40, 135))
                .endRow(false)
                .addEmptyRow(20D)
                .addRow(GirdCell.createCell(1, Pos.CENTER), GirdCell.createCell(4, Pos.CENTER_LEFT), GirdCell.createCell(4, Pos.CENTER_LEFT),
                        GirdCell.createCell(1, Pos.CENTER))
                .addCell(1, ControlsHelper.createCheckBox("记住我"))
                .endRow(false)
                .addEmptyRow(20D)
                .addRow(GirdCell.createCell(1, Pos.CENTER), GirdCell.createCell(8, Pos.CENTER), GirdCell.createCell(1, Pos.CENTER))
                .coverCell(1, ControlsHelper.createBtn("登录", "btn-info", "h5"))
                .endRow(false)
                .build();
        return loginForm;
    }

    @Override
    public void start(Stage stage) throws Exception {
        //系统图一
        ImageView background = new ImageView(new Image("img/bg_7.jpg"));
        //系统图二
        WritableImage writableImage = background.snapshot(new SnapshotParameters(), null);
        ImageView glassView = new ImageView(writableImage);
        Effect frostEffect = new BoxBlur(60, 60, 100);
        glassView.setEffect(frostEffect);

        Scene scene = new Scene(new StackPane(glassView, show()));
        stage.setScene(scene);
        stage.show();
    }
}
